Sign Up
Authentication
Sign Up
Create a new user account and receive JWT authentication tokens
POST
Sign Up
Overview
The sign-up endpoint creates a new user account in the Password Generator application. Upon successful registration, the endpoint returns JWT access and refresh tokens along with the user’s information.Endpoint
Request Body
Unique username for the account. This field is required by Django’s AbstractUser model.
User’s email address. Must be unique in the system.
User’s password. Will be securely hashed using Django’s password hashing system.
User’s first name. Defaults to empty string if not provided.
User’s last name. Defaults to empty string if not provided.
User’s phone number. Maximum 10 characters. Can be null.
Response
JWT access token used for authenticating API requests. Short-lived token.
JWT refresh token used to obtain new access tokens when they expire.
User object containing the created user’s information.
Unique identifier for the user.
User’s username.
User’s email address.
User’s first name.
User’s last name.
User’s phone number.
URL to user’s avatar image (if uploaded).
Example Request
cURL
Python
JavaScript
Example Response
201 Created
Error Responses
400 Bad Request - Missing Fields
400 Bad Request - Validation Error
500 Internal Server Error
Implementation Details
The sign-up endpoint is implemented inapps/users/views.py:49-79. Here’s how it works:
- Validation: The request data is validated against the
UsersSerializer - User Creation: If valid, a new user is created with the provided data
- Password Hashing: The password is securely hashed using
user.set_password() - Token Generation: JWT tokens are generated using
RefreshToken.for_user(user) - Response: Returns both tokens and the complete user object
Code Reference
Fromapps/users/views.py:49-79:
Notes
- This endpoint does not require authentication (
@permission_classes([AllowAny])) - The password is automatically hashed and never stored in plain text
- Both access and refresh tokens are returned immediately upon successful registration
- The user model extends Django’s
AbstractUser(defined inapps/users/models.py:5)
